<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" @submit.native.prevent v-show="showSearch" label-width="68px">
        <el-form-item label="单据编号【同一个企业不能上传相同单据号】" prop="billCode">
          <el-input
            v-model="queryParams.billCode"
            placeholder="请输入单据编号【同一个企业不能上传相同单据号】"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="单据时间" prop="billTime">
          <el-date-picker clearable
            v-model="queryParams.billTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择单据时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['barcode:uploadcircubill:add']"
          >新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="success"
            plain
            icon="el-icon-edit"
            size="mini"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['barcode:uploadcircubill:edit']"
          >修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="danger"
            plain
            icon="el-icon-delete"
            size="mini"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['barcode:uploadcircubill:remove']"
          >删除</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['barcode:uploadcircubill:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="uploadcircubillList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="序号" type="index" width="50" />
        <af-table-column label="id" align="center" prop="id" />
        <el-table-column label="单据编号【同一个企业不能上传相同单据号】" align="center" prop="billCode" />
        <el-table-column label="单据时间" align="center" prop="billTime" min-width="152">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.billTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="单据类型【102代表采购入库,201代表销售出库，其它单据类型详见文档】" align="center" prop="billType" />
        <el-table-column label="药品类型【3普药2特药】" align="center" prop="physicType" />
        <af-table-column label="货主企业" align="center" prop="refUserId" />
        <el-table-column label="第三方物流代理企业" align="center" prop="agentRefUserId" />
        <el-table-column label="发货企业" align="center" prop="fromUserId" />
        <el-table-column label="收货企业" align="center" prop="toUserId" />
        <el-table-column label="直调企业" align="center" prop="destUserId" />
        <el-table-column label="操作人标识" align="center" prop="operIcCode" />
        <el-table-column label="单据提交者姓名" align="center" prop="operIcName" />
        <el-table-column label="单据文件体【bas64字符串】" align="center" prop="fileContent" />
        <el-table-column label="单据名称" align="center" prop="uploadFileName" />
        <el-table-column label="请求端类型【暂定都写2】" align="center" prop="clientType" />
        <el-table-column label="发货地址" align="center" prop="fromAddress" />
        <el-table-column label="收货地址" align="center" prop="toAddress" />
        <el-table-column label="发货单编号" align="center" prop="fromBillCode" />
        <el-table-column label="订货单编号" align="center" prop="orderCode" />
        <el-table-column label="发货人" align="center" prop="fromPerson" />
        <el-table-column label="收货人" align="center" prop="toPerson" />
        <el-table-column label="药品配送企业refentid" align="center" prop="disRefEntId" />
        <el-table-column label="药品配送企业entId" align="center" prop="disEntId" />
        <el-table-column label="应收货总数量" align="center" prop="quReceivable" />
        <el-table-column label="是否验证，0：未通过验证，1：已验证" align="center" prop="xtIsCheck" />
        <el-table-column label="未验证通过原因" align="center" prop="xtCheckCode" />
        <el-table-column label="未验证通过原因描述" align="center" prop="xtCheckCodeDesc" />
        <el-table-column label="药品列表Json" align="center" prop="drugListJson" />
        <el-table-column label="单据委托企业refEntId" align="center" prop="assRefEntId" />
        <el-table-column label="单据委托企业entId" align="center" prop="assEntId" />
        <el-table-column label="创建人" align="center" prop="createBy" min-width="100"/>
        <el-table-column label="创建时间" align="center" prop="createTime" min-width="152" />
        <el-table-column label="最后更新人" align="center" prop="updateBy" min-width="100"/>
        <el-table-column label="最后更新时间" align="center" prop="updateTime" min-width="152" />
      </el-table>
      
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
  
      <!-- 添加或修改监管码对话框 -->
      <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="单据编号【同一个企业不能上传相同单据号】" prop="billCode">
            <el-input v-model="form.billCode" placeholder="请输入单据编号【同一个企业不能上传相同单据号】" />
          </el-form-item>
          <el-form-item label="单据时间" prop="billTime">
            <el-date-picker clearable
              v-model="form.billTime"
              type="date"
              value-format="yyyy-MM-dd"
              placeholder="请选择单据时间">
            </el-date-picker>
          </el-form-item>
          <el-form-item label="第三方物流代理企业" prop="agentRefUserId">
            <el-input v-model="form.agentRefUserId" placeholder="请输入第三方物流代理企业" />
          </el-form-item>
          <el-form-item label="发货企业" prop="fromUserId">
            <el-input v-model="form.fromUserId" placeholder="请输入发货企业" />
          </el-form-item>
          <el-form-item label="收货企业" prop="toUserId">
            <el-input v-model="form.toUserId" placeholder="请输入收货企业" />
          </el-form-item>
          <el-form-item label="直调企业" prop="destUserId">
            <el-input v-model="form.destUserId" placeholder="请输入直调企业" />
          </el-form-item>
          <el-form-item label="操作人标识" prop="operIcCode">
            <el-input v-model="form.operIcCode" placeholder="请输入操作人标识" />
          </el-form-item>
          <el-form-item label="单据提交者姓名" prop="operIcName">
            <el-input v-model="form.operIcName" placeholder="请输入单据提交者姓名" />
          </el-form-item>
          <el-form-item label="单据文件体【bas64字符串】">
            <editor v-model="form.fileContent" :min-height="192"/>
          </el-form-item>
          <el-form-item label="单据名称" prop="uploadFileName">
            <el-input v-model="form.uploadFileName" placeholder="请输入单据名称" />
          </el-form-item>
          <el-form-item label="发货地址" prop="fromAddress">
            <el-input v-model="form.fromAddress" placeholder="请输入发货地址" />
          </el-form-item>
          <el-form-item label="收货地址" prop="toAddress">
            <el-input v-model="form.toAddress" placeholder="请输入收货地址" />
          </el-form-item>
          <el-form-item label="发货单编号" prop="fromBillCode">
            <el-input v-model="form.fromBillCode" placeholder="请输入发货单编号" />
          </el-form-item>
          <el-form-item label="订货单编号" prop="orderCode">
            <el-input v-model="form.orderCode" placeholder="请输入订货单编号" />
          </el-form-item>
          <el-form-item label="发货人" prop="fromPerson">
            <el-input v-model="form.fromPerson" placeholder="请输入发货人" />
          </el-form-item>
          <el-form-item label="收货人" prop="toPerson">
            <el-input v-model="form.toPerson" placeholder="请输入收货人" />
          </el-form-item>
          <el-form-item label="药品配送企业refentid" prop="disRefEntId">
            <el-input v-model="form.disRefEntId" placeholder="请输入药品配送企业refentid" />
          </el-form-item>
          <el-form-item label="药品配送企业entId" prop="disEntId">
            <el-input v-model="form.disEntId" placeholder="请输入药品配送企业entId" />
          </el-form-item>
          <el-form-item label="应收货总数量" prop="quReceivable">
            <el-input v-model="form.quReceivable" placeholder="请输入应收货总数量" />
          </el-form-item>
          <el-form-item label="是否验证，0：未通过验证，1：已验证" prop="xtIsCheck">
            <el-input v-model="form.xtIsCheck" placeholder="请输入是否验证，0：未通过验证，1：已验证" />
          </el-form-item>
          <el-form-item label="未验证通过原因" prop="xtCheckCode">
            <el-input v-model="form.xtCheckCode" placeholder="请输入未验证通过原因" />
          </el-form-item>
          <el-form-item label="未验证通过原因描述" prop="xtCheckCodeDesc">
            <el-input v-model="form.xtCheckCodeDesc" placeholder="请输入未验证通过原因描述" />
          </el-form-item>
          <el-form-item label="药品列表Json" prop="drugListJson">
            <el-input v-model="form.drugListJson" type="textarea" placeholder="请输入内容" />
          </el-form-item>
          <el-form-item label="单据委托企业refEntId" prop="assRefEntId">
            <el-input v-model="form.assRefEntId" placeholder="请输入单据委托企业refEntId" />
          </el-form-item>
          <el-form-item label="单据委托企业entId" prop="assEntId">
            <el-input v-model="form.assEntId" placeholder="请输入单据委托企业entId" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </el-dialog>
    </div>
  </template>
  
  <script>
  import { listUploadcircubill, getUploadcircubill, delUploadcircubill, addUploadcircubill, updateUploadcircubill } from "@/api/uploadcircubill/index";
  
  export default {
    name: "Uploadcircubill",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        selections: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 监管码表格数据
        uploadcircubillList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          billCode: null,
          billTime: null,
          billType: null,
          physicType: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          billCode: [
            { required: true, message: "单据编号【同一个企业不能上传相同单据号】不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询监管码列表 */
      getList() {
        this.loading = true;
        listUploadcircubill(this.queryParams).then(response => {
          this.uploadcircubillList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          billCode: null,
          billTime: null,
          billType: null,
          physicType: null,
          refUserId: null,
          agentRefUserId: null,
          fromUserId: null,
          toUserId: null,
          destUserId: null,
          operIcCode: null,
          operIcName: null,
          fileContent: null,
          uploadFileName: null,
          clientType: null,
          fromAddress: null,
          toAddress: null,
          fromBillCode: null,
          orderCode: null,
          fromPerson: null,
          toPerson: null,
          disRefEntId: null,
          disEntId: null,
          quReceivable: null,
          xtIsCheck: null,
          xtCheckCode: null,
          xtCheckCodeDesc: null,
          drugListJson: null,
          assRefEntId: null,
          assEntId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.selections = selection
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加监管码";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getUploadcircubill(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改监管码";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateUploadcircubill(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addUploadcircubill(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.resetQuery();
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除"' + ids.length + '"条数据项？').then(function() {
          return delUploadcircubill(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('barcode/uploadcircubill/export', {
          ...this.queryParams
        }, `uploadcircubill_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  